﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Cellula.Biz;
using Cn.Cellula.Model;
using Cn.Edwon.Web;
using System.Collections.Generic;
using Cn.Edwon.Web.Validation;
using Cn.Edwon.Biz;
using Cn.Cellula.Model.Product;
using Cn.Cellula.Client;
namespace Cn.Cellula.Website.Admin.Product.Group {
    public partial class Edit : PageSupport {
        String EOKey = null;
        IBiz biz = BizFactory.Get<IBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            EOKey = Request.QueryString["id"];
            if (!Page.IsPostBack) {
                if (!String.IsNullOrEmpty(EOKey)) {
                    FillForm(EOKey);
                }
            }
        }
        private void FillForm(String rKey) {
            TProductGroupEO eo = biz.Load<TProductGroupEO>(rKey);
            this.txt_Alias.Text = eo.GroupAlias;
            this.txt_Desc.Text = eo.Description;
            this.txt_Name.Text = eo.GroupName;
        }
        protected void btn_save_Click(object sender, EventArgs e) {
            Boolean vd = QuickValidator.Execute(Request, this.txt_Name.Parent);
            if (!vd) {
                SiteInfo.Send(Page, TxtDef.ERROR, QuickValidator.Message);
                return;
            }
            if (String.IsNullOrEmpty(EOKey)) {
                TProductGroupEO eo = new TProductGroupEO();
                eo.CreateDate = DateTime.Now;
                eo.CreateOperator = (this.Actor == null) ? "unknown" : this.Actor.ID;
                eo.Description = this.txt_Desc.Text;
                eo.GroupAlias = this.txt_Alias.Text;
                eo.GroupName = this.txt_Name.Text;
                eo.LastDate = DateTime.Now;
                eo.OwnerKey = this.OwnerKey;
                eo.UpdateOperator = (this.Actor == null) ? "unknown" : this.Actor.ID;
                biz.Save<TProductGroupEO>(eo);
            } else {
                TProductGroupEO eo = biz.Load<TProductGroupEO>(EOKey);
                eo.UpdateOperator = (this.Actor == null) ? "unknown" : this.Actor.ID;
                eo.LastDate = DateTime.Now;
                eo.GroupName = this.txt_Name.Text;
                eo.GroupAlias = this.txt_Alias.Text;
                eo.Description = this.txt_Desc.Text;
            }
            SiteInfo.SendSucceed(Page, "List.aspx");
        }
    }
}
